home *** CD-ROM | disk | FTP | other *** search
- Path: newsxfer2.itd.umich.edu!caen!hasdi
- From: hasdi@news-server.engin.umich.edu (HASDI RODZMANN HASHIM)
- Newsgroups: alt.msdos.programmer,comp.lang.c,comp.lang.pascal.misc
- Subject: Re: typecasting preferences
- Followup-To: alt.msdos.programmer,comp.lang.c,comp.lang.pascal.misc
- Date: 18 Apr 1996 05:53:47 GMT
- Organization: University of Michigan Engineering, Ann Arbor
- Distribution: world
- Message-ID: <4l4ldb$nkl@srvr1.engin.umich.edu>
- References: <4l020g$i9j@srvr1.engin.umich.edu> <Pine.A32.3.91.960416145209.106109C-100000@black.weeg.uiowa.edu>
- NNTP-Posting-Host: neon.engin.umich.edu
- X-Newsreader: TIN [version 1.2 PL2]
-
- The Amorphous Mass (robinson@blue.weeg.uiowa.edu) wrote:
- : On 16 Apr 1996, HASDI RODZMANN HASHIM wrote:
-
- : C-style. Especially since C types can contain multiple tokens;
-
- : const char *(p) is less clear IMO than (const char *)p.
-
- Hmm.... another thing about pascal is that dereferencer is postfix
- instead of prefix. That way, I can cast a void * (Pascal - pointer) into
- something else...
-
- C-style:
- typedef myrecord_s {...} myrecord,*myrec;
-
- my_int = ((myrecord*)myvar)->intA; /* yeach! */
- or...
- my_int = (*(myrecord*)myvar).intA; /* see above */
-
- Pascal-syle:
- myrecp : ^myrecord;
- myrecord : record ... end;
-
- myInt := myrecp(myvar)^.intA; { looks clean }
- myInt := ^myrecord(myvar)^.intA; { compile error? }
-
- Remix:
- my_int = myrecp(myvar)*.intA;
- or...
- my_int = myrecord*(myvar)*.intA; /* ouch! */
-
- Some people mentioned about type-casting != type-conversion and C++ use
- makes distinction between them using cast-notation (c-style) and
- function-notation (pascal-style). I think I am getting the hang of the
- differences; I had to talk to my professor and read C++ draft to figure
- out what it going on.
-
- The way I understand it, type-conversion is to transform the bits of one
- variable so that it is representable as the type to be converted into. eg.
- (int)my_float. type-casting doesn't transform the bits at all, but force
- the compiler to treat that variable as the specified type... which is
- highly unportable. Why would anyone want to typecast then? Can somebody
- clarify this for me?
-
- As a side note, using typedef so that you can use "myrecord" instead of
- "struct myrecord_s" has been a real major bug to me. Unfortunately, this
- is necessary to avoid shift/reduce conflicts. Makes me wonder how C++
- parser works. (If I stick to Pascal-style, this would also mean I have to
- redesign the declaration section, C-style or Pascal? But that's another
- story.)
-
- Thanks guys!
-
- Hasdi
-
-